package cn.brian.modular.sys.controller;

import cn.brian.modular.sys.entity.SysUser;
import cn.brian.modular.sys.service.SysUserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * A07_用户表控制层,只负责跳转,不操作数据库
 * 
 * @author 黄景华
 * @date 2018-03-21 04:24:27
 */
@RestController(value="sysUserController")
@RequestMapping("/sys/user")
public class SysUserController {
	Logger logger = LoggerFactory.getLogger(SysUserController.class);

	@Autowired
	private SysUserService sysUserService;

  /**
   * 查询用户列表
   *
   * @param sysUser sysUser
   * @return List
   */
  @RequestMapping(value = "/listSysUser", method = RequestMethod.POST)
  public List<SysUser> listSysUser(@RequestBody SysUser sysUser) {
    return this.sysUserService.listUserWithoutPage(sysUser);
  }
	
	/**
	 * 保存
	 * @param sysUser
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value ="/save", method = RequestMethod.POST)
	public void saveUser(String userId) throws Exception{
		SysUser sysUser=new SysUser();
		sysUser.setUserId(userId);
		sysUser.setLoginName(userId);
		sysUser.setRoleId(userId);
		sysUser.setOrgId(userId);
		sysUser.setOrgLevelCode(userId);
		sysUser.setSex("1");
		sysUser.setStatus("1");
		sysUser.setTel("121231");
		sysUser.setPassword("2312");
		sysUser.setUserName(userId);
		sysUser.setSortNo(1);
		sysUserService.preSaveUser(sysUser);
	}
	
	/**
	 * 修改
	 * @param sysUser
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value ="/update", method = RequestMethod.POST)
	public void updateUser(@RequestBody SysUser sysUser) throws Exception{

		sysUserService.updateUser(sysUser);
	}
	
	/**
	 * 删除
	 * @param userIds
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value ="/delete", method = RequestMethod.POST)
	public void deleteUser(@RequestBody String userIds) throws Exception{

		sysUserService.deleteUser(userIds);
	}


	/**
	 * 查询
	 * 
	 * @param userId
	 *            查询条件
	 * @return SysDict
	 * @throws Exception 
	 */
	@RequestMapping(value = "/findUserByUserId", method = RequestMethod.GET)
	public SysUser findUserByUserId(String userId) throws Exception {
		
		return  sysUserService.findUserByUserId(userId);
	}
	

}
